package com.dotto.atos.ui;

import java.util.List;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.dotto.atos.fragments.ImageViewFragment;

/**
 * The <code>PagerAdapter</code> serves the fragments when paging.
 * 
 * @author mwho
 */
public class PagerAdapter extends FragmentPagerAdapter {

	private List<Fragment> fragments;

	/**
	 * @param fm
	 * @param fragments
	 */
	public PagerAdapter(FragmentManager fm, List<Fragment> fragments) {
		super(fm);
		this.fragments = fragments;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.support.v4.app.FragmentPagerAdapter#getItem(int)
	 */
	@Override
	public Fragment getItem(int position) {
		Fragment f = this.fragments.get(position);
		if (f != null && f instanceof ImageViewFragment) {
			ImageViewFragment f2 = (ImageViewFragment) f;
			if (position == 0) {
				f2.setImage(com.dotto.atos.R.drawable.slide1);
			} else if (position == 1) {
				f2.setImage(com.dotto.atos.R.drawable.slide2);
			} else if (position == 2) {
				f2.setImage(com.dotto.atos.R.drawable.slide3);
			} else {
				f2.setImage(com.dotto.atos.R.drawable.slide3);
			}
		}
		return this.fragments.get(position);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.support.v4.view.PagerAdapter#getCount()
	 */
	@Override
	public int getCount() {
		return this.fragments.size();
	}
}